package cn.boltzjf.sql4j.examples.postgres.dao;

import static cn.boltzjf.sql4j.coltype.DefaultColumnTypes.JSON;

import java.sql.Connection;

import org.postgresql.util.PGobject;

import cn.boltzjf.sql4j.dao.Dao;
import cn.boltzjf.sql4j.dao.ValueConverter;
import cn.boltzjf.sql4j.ext.postgres.PgTypeUtils;

public abstract class BaseDao extends Dao {

    static {
        PgTypeUtils.VALUE_CONVERTER.registerDbValueReader(JSON, (s, t) -> {return PGobject.class.isInstance(s) ? s.toString() : s;});
        PgTypeUtils.VALUE_CONVERTER.registerDbValueWriter(JSON, (s, t) -> {return String.class.isInstance(s) ? PgTypeUtils.jsonb((String)s) : s;});
    }
    
    protected ValueConverter valueConverter() {
        return PgTypeUtils.VALUE_CONVERTER;
    }

    @Override
    protected Connection getConnection() {
        return null;
    }

}
